function reversWords(words) {
  const length = words.length
  let temp = ''
  const stack = []
  for(let i=0; i< length; i++ ) {
    if(words[i] != ' ') {
      temp+= words[i]
    }else {
      if(temp !== '') stack.push(temp)
      temp = ''
    }
  }
  if(temp !== '') stack.push(temp)
  console.log(stack)
  let result = ''
  while(stack.length){
    result += stack.pop() + ' '
  }
  return result

  // let arr = words.split(' ')
  // arr = arr.filter((item)=> {
  //   return item !== ''
  // })
  // console.log(arr)
  // let end = ''
  // while(arr.length) {
  //   end = end + arr.pop() + ' '
  // }
  // return end
}

console.log(reversWords('This is a   good example'))